package com.peak.config.provider;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 主题型交换机、队列配置
 */
@Configuration
public class TopicRabbitConfig {

    @Bean
    public Queue geoQueue() {
        return new Queue("geo.inout.queue");
    }

    @Bean
    public TopicExchange geoExchange() {
        return new TopicExchange("geo-exchange");
    }

    /**
     * 将队列和交换机绑定,而且绑定的键值为geo.key.inout
     * 这样只要是消息携带的路由键是geo.key.inout,才会分发到该队列
     */
    @Bean
    Binding bindingGeoExchange() {
        return BindingBuilder.bind(geoQueue()).to(geoExchange()).with("geo.key.inout");
    }
}
